<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Console\Command;

class UserTopics extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'user:topics {num}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'User Topics';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->info('start');
        $this->ini($this->argument('num'));
        $this->info('end');
    }

    public function ini($num)
    {
        $data = User::with('topics')->limit($num)->get();
        DB::connection('mongodb')->collection('users')->insert($data->toArray());
        //$data = DB::connection('mongodb')->collection('users')->where('id', intval($num))->select('id', 'name', 'topics.body')->first();
    }
}
